
# from wordcloud import WordCloud

# wc = WordCloud(
#     background_color='white'
# )    # 创建词云对象
# wc.generate('This is not the end. It is not even the beginning of the end. But it is, perhaps, the end of the beginning.')    # 生成词云
# wc.to_file('wc.png')    # 保存词云
# 
# import numpy as np
# # import matplotlib.pyplot as plt
# from wordcloud import WordCloud

# text = "square"

# x, y = np.ogrid[:300, :300]

# mask = (x - 150) ** 2 + (y - 150) ** 2 > 130 ** 2
# mask = 255 * mask.astype(int)


# wc = WordCloud(background_color="white", repeat=True, mask=mask)
# wc.generate(text)
# wc.to_file('wc.png')
# plt.axis("off")
# plt.imshow(wc, interpolation="bilinear")
# plt.show()
# 
import os

from os import path
from wordcloud import WordCloud

d = path.dirname(__file__) if "__file__" in locals() else os.getcwd()
text = open(path.join(d, 'test.txt')).read()
text=text.lower()
# wordcloud = WordCloud().generate(text)
wordcloud = WordCloud(background_color="white",width=800,height=660).generate(text)
import matplotlib.pyplot as plt
# plt.imshow(wordcloud, interpolation='bilinear')
# plt.axis("off")


plt.imshow(wordcloud)
plt.axis("off")
plt.show()
wordcloud.to_file('test.png')